﻿@using OF.JsonRpc
@using OF.JsonRpc.ExtensionInject
@using OF.JsonRpc.Util

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
@{
    var ipList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
    foreach (var ip in ipList)
    {
        if (ip != null)
        {
            var strArray = ip.ToString().Split('.');
            <text><!--@strArray[strArray.Length - 1]--></text>
        }
    }
}
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>JSON-RPC Help</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet"/>
    <link href="~/Content/styles.css" rel="stylesheet"/>
    <style type="text/css">
        .hl { background-color: yellow }
        .searchable td {
            border-top: dashed 1px #ebeaea !important;
        }
        .intervalClazzRow td {
            border-top: solid 1px #dcd9d9 !important;
            padding: 24px;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default" role="banner">
    <div class="container">
        <div class="navbar-header" class="text-center">
            <h2>
                @Html.ActionLink("JSON-RPC Help", "Index")
            </h2>
        </div>
    </div>
</nav>

<div class="container">
    <p>
        <a href="http://www.jsonrpc.org/specification">JSON-RPC 2.0 Specification(English)</a>,
        <a href="http://wiki.geekdream.com/Specification/json-rpc_2.0.html">(译) JSON-RPC 2.0 规范(中文版)</a>
    </p>

    <div class="input-group">
        <span class="input-group-addon">
            @{
                var services = Handler.DefaultHandler.MetaData.Services.OrderBy(s => s.Key);
            } @services.Count() Services, Filter
        </span>

        <input id="filter" type="text" class="form-control" placeholder="Type here...">
    </div>
    <table class="table">
        <thead>
        <tr>
            <th style="width: 25%">Method</th>
            <th>Description</th>
            @*<th>Parameters</th>
            <th>Return</th>*@
        </tr>
        </thead>
        <tbody class="searchable">
        @{
            string lastMethodName = null;
            string lastClazz = null;
            foreach (KeyValuePair<string, SMDService> keyValuePair in services)
            {
                string methodName = keyValuePair.Key;
                var smdService = keyValuePair.Value;
                var methodXmlComment = AssemlbyCommentReader.GetMethodComment(OF.JsonRpc.Handler.DefaultHandler.Handlers[methodName].Method);
                string clazz = "";

                if (lastMethodName != null)
                {
                    string[] lastMethodNameWords = lastMethodName.Split('.');
                    string[] thisMethodNameWords = methodName.Split('.');
                    bool isChangeInterval = false;
                    if (lastMethodNameWords.Length != thisMethodNameWords.Length)
                    {
                        isChangeInterval = true;
                    }
                    else if (thisMethodNameWords.Length == 1)
                    {
                        isChangeInterval = false;
                    }
                    else
                    {
                        for (int i = 0; i < thisMethodNameWords.Length - 1; i++)
                        {
                            if (thisMethodNameWords[i] != lastMethodNameWords[i])
                            {
                                isChangeInterval = true;
                                break;
                            }
                        }
                    }

                    if (isChangeInterval)
                    {
                        clazz = "intervalClazzRow";
                    }
                }

                lastMethodName = methodName;
                lastClazz = clazz;

                <tr class="@clazz">
                    <td>
                        <a href="method?name=@Url.Encode(methodName)" target="_blank" class="link btn-link">
                            <span>@methodName</span>
                        </a>
                    </td>
                    <td>
                        <span style="color: gray">@AssemlbyCommentReader.GetMethodDescprtionComment(methodXmlComment)</span>
                    </td>
                    @*<td>
        @{
            foreach (SMDAdditionalParameters param in smdService.parameters)
            {
                <code class="small" style="margin-right: 10px">
                    <span style="color: blue">@AssemlbyCommentReader.GetCSharpRepresentation(param.ObjectType)</span>
                    <span style="color: cadetblue">@param.Name</span>
                    <span style="color: gray">@AssemlbyCommentReader.GetMethodParameterComment(methodXmlComment, param.Name)</span>
                </code>
            }
        }
    </td>
    <td>
        <code class="small">
            <span style="color: blue">@AssemlbyCommentReader.GetCSharpRepresentation(smdService.returns.ObjectType)</span>
            <span style="color: gray">@AssemlbyCommentReader.GetMethodReturnsComment(methodXmlComment)</span>
        </code>
    </td>*@
                </tr>
            }
        }
        </tbody>
    </table>
</div>

<script src="~/Scripts/jquery.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/scripts.js"></script>
<script>
    $(document).ready(function() {

        (function($) {

            $('#filter').keyup(function() {

                var rex1 = new RegExp($(this).val(), 'i');
                var rex2 = new RegExp('(' + $(this).val() + ')', 'i');
                var rex3 = new RegExp('<span class="hl">(.*)</span>', 'i');

                $('.searchable tr').hide();
                $('.searchable tr td span').each(function(index, value) {
                    value.innerHTML = value.innerHTML.replace(rex3, "$1");
                });
                $('.searchable tr').filter(function() {
                    return rex1.test($(this).text());
                }).show();
                $('.searchable tr td span').each(function(index, value) {
                    value.innerHTML = value.innerHTML.replace(rex2, '<span class="hl">$1</span>');
                });
            })

        }(jQuery));

    });
</script>
</body>
</html>